package com.qf.controller;

import com.qf.pojo.Grade;
import com.qf.service.GradeService;
import com.qf.utils.ResultMsg;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 年级控制器
 */
@Controller
@ResponseBody
@RequestMapping("/grade")
public class GradeController {
    @Autowired
    GradeService gradeService;

    /**
     * 全查所有年级
     * @return
     */
    @RequestMapping("/selectAll")
    public ResultMsg selectAll(@RequestParam(name = "page",defaultValue = "1",required = false) Integer page,@RequestParam(name = "limit",required = false,defaultValue = "10") Integer limit){
        return gradeService.selectAll(page,limit);
    }

    /**
     * 查询一个年级的信息
     * @param gradeId
     * @return
     */
    @RequestMapping("/selectOne")
    public ResultMsg selectOne(Integer gradeId){
        return gradeService.selectOne(gradeId);
    }

    /**
     * 修改一个年级信息
     * @param grade
     * @return
     */
//    @RequestMapping("/changeGrade")
    @PutMapping("/changeGrade")
    public ResultMsg changeGrade(@RequestBody Grade grade){
        return gradeService.changeGrade(grade);
    }

    /**
     * 新增一个年级
     * @param grade
     * @return
     */
//    @RequestMapping("/addGrade")
    @PutMapping("/addGrade")
    public ResultMsg addGrade(@RequestBody Grade grade){
        return gradeService.addGrade(grade);
    }

    /**
     * 修改年级状态
     * @param gradeId
     * @return
     */
    @RequestMapping("/changeGradeStatus")
    public ResultMsg changeGradeStatus(Integer gradeId){
        return gradeService.changeGradeStatus(gradeId);
    }

    /**
     * 模糊查询（根据年级名称和状态）
     * @param name
     * @param status
     * @return
     */
    @RequestMapping("/find")
    public ResultMsg find(String name,String status){
        return gradeService.find(name,status);
    }

    /**
     * 删除课程
     * @return
     */
    @DeleteMapping("/deleteGrade")
    public ResultMsg deleteGrade(@RequestBody Map<String, List<Integer>> map){
//        String key="gradeId";
        return gradeService.deleteGrade(map.get("gradeId"));
    }
}
